<template>
    <div>
  <el-form :model="adminForm" :rules="rules" ref="updateadminFormRef" label-width="20%" >
    <el-form-item label="用户名" prop="username">
      <el-input v-model="adminForm.username"></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="password">
      <el-input v-model="adminForm.password" ></el-input>
    </el-form-item>
    <el-form-item label="角色" >
      <el-input :value="adminForm.type===1?'超级管理账号':(adminForm.type===2?'管理账号':'普通账号')" disabled></el-input>
    </el-form-item>
    <el-form-item label="手机号" prop="phone">
      <el-input v-model="adminForm.phone"></el-input>
    </el-form-item>
  </el-form></div>
  </template>
  <script>
  import formCheck from'@/js/formCheck.js'
  export default {
      data() {
        return {
          adminForm: {
            username: '',
            password:'',
            phone:'',
            type:'',
            createAdminId:''
          },
          rules: {
              username: [
           { required: true, validator:formCheck.usernameCheck, trigger: 'blur' },
           
          ],
          // 密码是否合法
          password: [
             {  validator:formCheck.passwordCheck, trigger: 'blur' },
           
          ],
          phone: [
            { validator:formCheck.phoneCheck, trigger: 'blur' }
          ],
          }
        };
      },
      methods: {
        admin1(upadmin1){
          this.adminForm=upadmin1
        },
        // 修改用户
        updateadmin(callback) {
  return new Promise(async (resolve) => {
    this.$refs.updateadminFormRef.validate(async (valid) => {
      if (!valid) {
        if (typeof callback === 'function') {
          callback(false);
        }
        resolve(false);
      } else {
        const res = await this.$api.rear_end.updateAdmin(this.adminForm)
        if (res.data.code === 1) {
          this.$message.success('修改账号成功！');
          if (typeof callback === 'function') {
            callback(true);
          }
          resolve(true);
        } else {
          this.$message.error('修改失败！');
          if (typeof callback === 'function') {
            callback(false);
          }
          resolve(false);
        }
      }
    });
  });
}

      }
     
  }
  </script>
  
  <style lang="less" scoped>
  
  
  
  </style>